package com.zmm.util.password;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * 密码安全帮助类
 * @author 900045
 * @description:
 * @name SecurityUtil
 * @date By 2021-07-26 16:27:15
 */
public final class SecurityUtil {

	static MessageDigest getDigest() {
		try {
			return MessageDigest.getInstance("MD5");
		} catch (NoSuchAlgorithmException e) {
			throw new RuntimeException(e);
		}
	}


	private SecurityUtil() {

	}

	/**
	 * 解密登录密码
	 * @author: 900045
	 * @date: 2021-07-26 16:46:25
	 * @throws 
	 * @param password: 
	 * @return: java.lang.String
	 **/
	public static String getDecryptLoginPassword(String password) {
		return PasswordUtil.getDecryptLoginPassword(password);
	}

	/**
	 * 生成密码安全码
	 *
	 * @return
	 * @author lihe 2012-9-27 上午9:40:51
	 * @see
	 */
	public static String getNewPsw() {
		String s1 = MdFiveUtil.md5Hex(String.valueOf(System.currentTimeMillis()));
		String s2 = UUIDUtil.getUUID();
		return s1 + s2;
	}

	public static String getStoreLoginPwd(String userCode, String logPwd, String psw) {
		return MdFiveUtil.md5Hex(userCode + MdFiveUtil.md5Hex(logPwd) + psw);
	}


	public static byte[] md5(String data, String charset) {
		if (charset == null) {
			return getDigest().digest(data.getBytes());
		}
		try {
			return getDigest().digest(data.getBytes(charset));
		} catch (UnsupportedEncodingException e) {
			throw new RuntimeException(e);
		}

	}
}
